<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Lich extends CI_Model {
	function __construct()
	{
		parent::__construct();
		$this->load->database();
	}
	//$date phải có định dạng YYYY-MM-DD
	function them_lich($date,$user,$noidung,$thoidiem)
	{
	$data=array(
	'id_nguoidung'=>$user,
	'ngay_lichlamviec'=>$date,
	'noidung_lichlamviec'=>$noidung,
	'thoidiem_lichlamviec'=>$thoidiem
	);
	$query=$this->db->insert('vtv4_lichlamviec',$data);
	if($query) 
		return $this->db->insert_id();
	else
		return false;
	}
	function them_danhsach_lich($data){
		return $this->db->insert('vtv4_danhsachlich',$data);
	}
	function sua_danhsach_lich($data,$id_lich){
		$this->db->where('id_danhsachlich',$id_lich);
		return $this->db->update('vtv4_danhsachlich',$data);
	}
	function del_danhsach_lich($id_lich){
		$this->db->where('id_danhsachlich',$id_lich);
		return $this->db->delete('vtv4_danhsachlich');
	}
	function sua_lich($id,$noidung)
	{
		$data=array(
		'noidung_lichlamviec'=>$noidung
		);
		$this->db->where('id_lichlamviec',$id);
		$query=$this->db->update('vtv4_lichlamviec',$data);
		return $query;
	}  
	function listLich(){
		$this->db->order_by('order_lich DESC');
		$query = $this->db->get('vtv4_danhsachlich');
		return $query->result();
	}
	function getLich($id_lich){
		$this->db->where('id_danhsachlich',$id_lich);
		$query = $this->db->get('vtv4_danhsachlich');
		return $query->row();
	}
}